//
//  CJBOSSRecommendCell.m
//  Boss
//
//  Created by admin on 2018/9/11.
//  Copyright © 2018年 admin. All rights reserved.
//

#import "CJBOSSRecommendCell.h"
@interface CJBOSSRecommendCell()
@property (strong, nonatomic) IBOutlet NSLayoutConstraint *imageWith;
@property (strong, nonatomic) IBOutlet NSLayoutConstraint *imageHeight;

@property (strong, nonatomic) IBOutlet UIImageView *recommendImageView;
@property (strong, nonatomic) IBOutlet UILabel *titleLabel;

@property (strong, nonatomic) IBOutlet UILabel *readCount;
@property (strong, nonatomic) IBOutlet UICollectionView *collectionView;

@property (strong, nonatomic) IBOutlet UIButton *priceBtn;
@property (strong, nonatomic) IBOutlet UILabel *shareCount;
@property (strong, nonatomic) IBOutlet UILabel *priceLabel;

@property (strong, nonatomic) IBOutlet UIView *imageViews;

@property (strong, nonatomic) IBOutlet UIImageView *shareImageView;




@end
@implementation CJBOSSRecommendCell

- (void)awakeFromNib {
    [super awakeFromNib];
    self.imageWith.constant = 145 *DUP;
    self.imageHeight.constant = 96 *DUP;
   // self.shareImageView.tintColor = [UIColor grayColor];
    // Initialization code
}
-(void)setRecommend:(CJBOSSRecommend *)recommend
{
    _recommend = recommend;
 //   self.shareCount.text = recommend.forwardNum;
    self.priceLabel.text = [NSString stringWithFormat:@"共享佣金：¥ %.2f",recommend.totalMoney.floatValue/1000.0];
    [self.recommendImageView sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@!default",recommend.url]] placeholderImage:nil];
    self.titleLabel.text = recommend.businessName;
    
    self.readCount.text = [NSString stringWithFormat:@"%@阅读量",recommend.browseNum];
    self.shareCount.text = recommend.transpondNum;
    self.priceBtn.hidden = NO;
    self.shareCount.hidden = NO;
    self.shareImageView.hidden = NO;
    if (recommend.type.intValue==3) {
        [self.priceBtn setTitle:@"已领完" forState:UIControlStateNormal];
        self.priceBtn.enabled = NO;
        [self.priceBtn setBackgroundColor:[UIColor hexStringToColor:@"#eaeaea" alpha:1.0]];
        [self.priceBtn setTitleColor:[UIColor hexStringToColor:@"#999999" alpha:1.0] forState:(UIControlStateNormal)];
    }else if (recommend.type.intValue==2){
        [self.priceBtn setTitle:@"领佣金" forState:UIControlStateNormal];
        self.priceBtn.enabled = YES;
        [self.priceBtn setBackgroundColor:[UIColor hexStringToColor:@"#d8593f" alpha:1.0]];
        [self.priceBtn setTitleColor:[UIColor hexStringToColor:@"#ffffff" alpha:1.0] forState:(UIControlStateNormal)];
    }else if (recommend.type.intValue==1){
        self.priceBtn.hidden = YES;
        self.priceLabel.text = [NSString stringWithFormat:@"有效点击 ：%@       当前分红：%@",recommend.viewNum,recommend.profitAmount];
        self.shareCount.hidden = YES;
        self.shareImageView.hidden = YES;
    }
    
    
    NSArray *imageArray = [recommend.userUrls componentsSeparatedByString:@","];
    // NSArray *imageArray = @[@"",@"",@"",@""];
    NSUInteger imageCount = self.imageViews.frame.size.width/20.0;
    
    NSLog(@"------------------------%ld",imageCount);
    if (kScreenWidth==320) {
        imageCount = 3;
    }else{
        imageCount = 5;
    }
    
    
    if (imageArray.count>imageCount) {
        int ImageViewX = 0;
        for (int i=0; i<imageCount
             ; i++) {
            UIImageView *imageView = [[UIImageView alloc]init];
            imageView.frame = CGRectMake(ImageViewX, 0, 20, 20);
            [self.imageViews addSubview:imageView];
            [imageView setCornerRadius:10.f];
            //imageView.backgroundColor = kColorMainColor;
            [imageView setBorderWithWidth:kLineHeight andColor:[UIColor hexStringToColor:@"#f7f7f7" alpha:1.0]];
            ImageViewX+=15;
            if (i==imageCount-1) {
                imageView.image = [UIImage imageNamed:@"更多头像_icon"];
            }else{
                [imageView sd_setImageWithURL:[NSURL URLWithString:imageArray[i]]];
            }
        }
    }else{
        int ImageViewX = 0;
        for (int i=0; i<imageArray.count
             ; i++) {
            UIImageView *imageView = [[UIImageView alloc]init];
            imageView.frame = CGRectMake(ImageViewX, 0, 20, 20);
            [self.imageViews addSubview:imageView];
            [imageView setCornerRadius:10.f];
            
            [imageView setBorderWithWidth:kLineHeight andColor:[UIColor hexStringToColor:@"#f7f7f7" alpha:1.0]];
            
            
            imageView.backgroundColor = kColorMainColor;
            ImageViewX+=15;
            [imageView sd_setImageWithURL:[NSURL URLWithString:imageArray[i]]];
            //            if (i==imageArray.count-1) {
            //
            //
            //            }else{
            //
            //            }
            
            
        }
        
        
        
    }
    
    
    
}

-(void)layoutSubviews
{
    NSLog(@"%@",NSStringFromCGRect(self.imageViews.frame));
    
    
    
    
    
    
    
    
    
    
    
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}
- (IBAction)clickPriceBtn:(id)sender {
    
    if ([self.delegate respondsToSelector:@selector(clickCommissionBtn:)]) {
        [self.delegate clickCommissionBtn:self];
    }
    
    
    
}






@end
